﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.Tools.SchemaComparer.Extractor;
using System.Data.OracleClient;

namespace Sinacor.Infra.Tools.SchemaExtractor.ResouceAccess
{
    public class Company
    {
        public List<Entity.Company> GetCompanies(DBConnectionInfo connInfo)
        {
            List<Entity.Company> ret = new List<Entity.Company>();
            StringBuilder sqlCommand = new StringBuilder();

            sqlCommand.Append(" SELECT CD_EMPRESA, NM_EMPRESA, CD_USUA_ORAC, CD_SENHA_ORAC FROM TGEEMPR");

            using (OracleConnection connection = new OracleConnection(connInfo.ConnString))
            {
                connection.Open();
                OracleCommand commnad = new OracleCommand(sqlCommand.ToString(), connection);
                OracleDataReader reader = commnad.ExecuteReader();

                while (reader.Read())
                {
                    ret.Add(new Entity.Company()
                    {
                        Code = reader.GetValue<int>("CD_EMPRESA"),
                        Name = reader.GetValue<string>("NM_EMPRESA"),
                        UserName = reader.GetValue<string>("CD_USUA_ORAC"),
                        Password = reader.GetValue<string>("CD_SENHA_ORAC")
                    });
                }
            }

            return ret;
        }
    }
}
